package com.project.code.spider.controller;

import java.util.Arrays;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import com.project.common.annotation.Log;
import com.project.common.core.template.BaseController;
import com.project.common.core.template.Result;
import javax.annotation.Resource;

import com.project.common.utils.bean.CopyObjectUtils;
import com.project.common.enums.BusinessType;
import com.project.code.spider.entity.po.SpiderPlatform;
import com.project.code.spider.entity.params.SpiderPlatformAddParams;
import com.project.code.spider.entity.params.SpiderPlatformEditParams;
import com.project.code.spider.entity.params.SpiderPlatformPageParams;
import com.project.code.spider.entity.export.SpiderPlatformExport;
import com.project.code.spider.entity.vo.SpiderPlatformVo;
import com.project.code.spider.service.SpiderPlatformService;
import com.project.common.utils.excel.ExcelUtil;
import com.project.common.core.page.Pager;

/**
 * AI调价-爬虫平台 Controller
 *
 * @author WangYan
 * @date 2023-05-14
 */
@Api(tags = "AI调价-爬虫平台")
@RestController
@RequestMapping("/spider/platform")
public class SpiderPlatformController extends BaseController {

    @Resource
    private SpiderPlatformService spiderPlatformService;

    @ApiOperation(value = "add")
    @PreAuthorize("@ss.hasPermi('spider:platform:add')")
    @Log(title = "AI调价-爬虫平台", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody @Valid SpiderPlatformAddParams params) {
        return Result.success(spiderPlatformService.insert(CopyObjectUtils.copyAtoB(params,SpiderPlatform.class)));
    }

    @ApiOperation(value = "edit")
    @PreAuthorize("@ss.hasPermi('spider:platform:edit')")
    @Log(title = "AI调价-爬虫平台", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody @Valid SpiderPlatformEditParams params) {
        return Result.success(spiderPlatformService.updateById(CopyObjectUtils.copyAtoB(params,SpiderPlatform.class)));
    }

    @ApiOperation(value = "delete")
    @PreAuthorize("@ss.hasPermi('spider:platform:remove')")
    @Log(title = "AI调价-爬虫平台", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable Long[] ids) {
        return Result.success(spiderPlatformService.delete(Arrays.asList(ids)));
    }

    @ApiOperation(value = "read")
    @PreAuthorize("@ss.hasPermi('spider:platform:query')")
    @GetMapping(value = "/{id}")
    public Result<SpiderPlatformVo> read(@PathVariable("id") Long id) {
        return Result.success(spiderPlatformService.read(id, SpiderPlatformVo.class));
    }

    @ApiOperation(value = "list")
    @PreAuthorize("@ss.hasPermi('spider:platform:list')")
    @GetMapping("/list")
    public Pager<SpiderPlatformVo> list(SpiderPlatformPageParams params) {
        startPage();
        List<SpiderPlatformVo> result = spiderPlatformService.list(params, SpiderPlatformVo.class);
        return toPage(result);
    }

    @ApiOperation(value = "export")
    @PreAuthorize("@ss.hasPermi('spider:platform:export')")
    @Log(title = "AI调价-爬虫平台", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public Result export(SpiderPlatformPageParams params) {
        List<SpiderPlatformExport> list = spiderPlatformService.list(params, SpiderPlatformExport.class);
        ExcelUtil<SpiderPlatformExport> util = new ExcelUtil<SpiderPlatformExport>(SpiderPlatformExport.class);
        return util.exportExcel(list, "platform");
    }

}
